package Actuator知识点;

import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;
/**
 * @description: 自定义 HealthIndicator
 * @Author lxs
 * @Date 2025/3/17 15:23
 */
@Component
public class CustomHealthIndicator implements HealthIndicator {

    @Override
    public Health health() {
        // 模拟检查逻辑（比如检查某个服务是否可用）
        boolean serviceRunning = checkServiceStatus();

        if (serviceRunning) {
            return Health.up()
                    .withDetail("service", "Running")
                    .build();
        } else {
            return Health.down()
                    .withDetail("service", "Down")
                    .withDetail("reason", "Service Unreachable")
                    .build();
        }
    }

    private boolean checkServiceStatus() {
        // 模拟服务状态检查
        return Math.random() > 0.5;
    }
}